<template>
  <el-dialog append-to-body :title="title" width="640px" :visible="visible" @close="handleClose">
    <el-form ref="form" :model="form" :rules="rules" class="white-card" label-width="120px">
      <el-form-item label="补正时限：" prop="limitDay">
        <el-input-number v-model="form.limitDay" controls-position="right" :min="1" :max="30" placeholder="最大时限不超过30日"></el-input-number>
        <!-- <el-input v-model="form.limitDay"  style="width: 90%"></el-input> -->
        日
      </el-form-item>
      <el-form-item label="补正内容：" prop="correctRequirement">
        <el-input v-model="form.correctRequirement" show-word-limit maxlength="300" placeholder="请输入补正要求" type="textarea" style="width: 100%; height: 150px"></el-input>
      </el-form-item>
    </el-form>
    <div class="split"></div>

    <div class="dialog-footer-btn">
      <el-button @click="handleClose" type="primary" plain>关闭</el-button>
      <el-button @click="handleSubmit" :loading="submitting" type="primary">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import * as mixins from "@/utils/mixins";
import * as workOrderApi from "@/api/workOrder/index";
import * as templateApi from "@/api/template";

export default {
  name: "replenishDialog",
  mixins: [mixins.dialog, mixins.form],
  props: {
    visible: Boolean,
    workOrderId: String,
    title: {
      type: String,
      default: "发起材料补正",
    },
  },
  data() {
    return {
      form: {
        limitDay: undefined,
        correctRequirement: "",
      },
      rules: {
        correctRequirement: [{ required: true, message: "请输入补正要求" }],
        limitDay: [{ required: true, message: "请输入时限" }],
      },
      submitting: false,
      pickerOptions: {
        disabledDate: (time) => time.getTime() < Date.now() - 86400000,
      },
    };
  },
  methods: {
    show() {
      /* 
        材料补正内容	1020
         材料举证内容	1022
      */
      let code = 1020;
      if (this.title === "发起材料补正") {
        code = 1020;
      } else {
        code = 1022;
      }
      templateApi.detailByCode(code).then((res) => {
        this.form.correctRequirement = res.result.value;
      });
    },
    handleSubmit() {
      this.validateAndConfirm("form")
        .then((res) => {
          this.submitting = true;
          return workOrderApi.distribute.updateMaterial({
            ...this.form,
            workOrderId: this.workOrderId,
          });
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
        })
        .finally(() => {
          this.submitting = false;
        });
    },
  },
};
</script>

<style scoped></style>
